/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package testing;

import clasificador.genetico.PoliticaCruce;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import utils.Couple;
import utils.Weighted;

/**
 *
 * @author e237573
 */
public class CruceString2 implements PoliticaCruce<ArrayList<Character>> {
    
    @Override
    public List<ArrayList<Character>> cruzar(Couple<Weighted<ArrayList<Character>>> pareja) {
        int lMin = Math.min(pareja.l().l().size(),pareja.r().l().size());
        ArrayList<Character> s1 = pareja.l().l();
        ArrayList<Character> s2 = pareja.r().l();
        
        ArrayList<Character> res1 = new ArrayList<Character>(lMin);
        ArrayList<Character> res2 = new ArrayList<Character>(lMin);
        
        for(int i = 0; i < lMin; i++)
        {
            int j = new Random().nextInt(2);
            if(j == 0)
            {
                res1.add(i,s1.get(i));
            } else {
                res1.add(i,s2.get(i));
            }
            
            j = new Random().nextInt(2);
            if(j == 0)
            {
                res2.add(i,s1.get(i));
            } else {
                res2.add(i,s2.get(i));
            }
        }
        
        ArrayList<ArrayList<Character>> res = new ArrayList<ArrayList<Character>>(2);
        res.add(res1);
        res.add(res2);
        
        return res;
    }
}
